jQuery(function($){
    var optionType = $("[name=worType]");
    var optionOId = $("[name=oId]");
    var type = $("#worType").val();
    var oId = $("#oId").val();
    var optionRank = $("[name=worRank]");
    var rank = $("#rank").val();
    /*var deleteFile = $("#deleteFile");
    var accessory = $("#accessory").val();*/



        $.ajax({
            type:"GET",
            url:"/sys/organization/organ",
            dataType:"text",
            success:function(data){
                optionOId.append("<option value=''>--请选择--</option>");
                var obj = JSON.parse(data);
                for(var i=0;i<obj.length;i++){
                    if (oId==obj[i].id){
                        optionOId.append("<option value="+obj[i].id+" selected>"+obj[i].fullName+"</option>");
                    } else{
                        optionOId.append("<option value="+obj[i].id+">"+obj[i].fullName+"</option>");
                    }
                }
            },
            error:function(data){
                alert("异常");
            }
        });

        $.ajax({
            type:"GET",
            url:"/sys/dictinary/listType",
            data:{type:'WOR_TYPE'},
            dataType:"text",
            success:function(data){
                optionType.append("<option value=''>--请选择--</option>");
                var obj = JSON.parse(data);
                for(var i=0;i<obj.length;i++){
                    if (type==obj[i].valueId){
                        optionType.append("<option value="+obj[i].valueId+" selected>"+obj[i].valueName+"</option>");
                    } else{
                        optionType.append("<option value="+obj[i].valueId+">"+obj[i].valueName+"</option>");
                    }
                }
            },
            error:function(data){
                alert("异常");
            }
        });

        $.ajax({
            type:"GET",
            url:"/sys/dictinary/listType",
            data:{type:'RANK_TYPE'},
            dataType:"text",
            success:function(data){
                optionRank.append("<option value=''>--请选择--</option>");
                var obj = JSON.parse(data);
                for(var i=0;i<obj.length;i++){
                    if (rank==obj[i].valueId){
                        optionRank.append("<option value="+obj[i].valueId+" selected>"+obj[i].valueName+"</option>");
                    } else{
                        optionRank.append("<option value="+obj[i].valueId+">"+obj[i].valueName+"</option>");
                    }
                }
            },
            error:function(data){
                alert("异常");
            }
        });

        /*deleteFile.click(function () {
            var deleteOrUpdate = $("#deleteOrUpdate");

            if (confirm("确定删除吗?")) {
                $.ajax({
                    type:"GET",
                    url:"/sys/wor/delFile",
                    data:{path:accessory},
                    dataType:"text",
                    success:function(data){
                        if(data=="true"){
                            alert("删除成功");
                            deleteOrUpdate.remove();
                        }else{
                            alert("删除失败");
                        }
                    },
                    error:function(data){
                        alert("对不起，删除失败");
                    }
                });
            }
        })*/


    function deleteFile (id) {
        var deleteOrUpdate = $("#deleteOrUpdate");
        if (confirm("确定删除吗?")) {
            $.ajax({
                type:"GET",
                url:"/sys/wor/delFile",
                data:{id:id},
                dataType:"text",
                success:function(data){
                    if(data=="true"){
                        alert("删除成功");
                        deleteOrUpdate.html("<label for='low'>试题附件：&nbsp;&nbsp;</label><input type=file class='form-control' name='attach' value=''> <small class='form-text text-muted'></small>");
                    }else{
                        alert("删除失败");
                    }
                },
                error:function(data){
                    alert("对不起，删除失败");
                }
            });
        }
    }
    window.deleteFile = deleteFile;

    function del (id) {
        var val = document.getElementById(id);
        if (confirm("确定删除吗?")) {
            $.ajax({
                type:"GET",
                url:"/sys/wor/delete",
                data:{id:id},
                dataType:"text",
                success:function(data){
                    if(data=="true"){
                        alert("删除成功");
                        val.remove();
                    }else{
                        alert("删除失败");
                    }
                },
                error:function(data){
                    alert("对不起，删除失败");
                }
            });
        }
    }
    window.del = del;

    queryList($("#formIndex").get(0), 1);
})